package org.gruposp2p.proyectokarma.gwt.client.event;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;

public class EventBusManager {
	
    private static EventBusManager instance;
    private HandlerManager handlerManager;

    private EventBusManager () {
        handlerManager = new HandlerManager (this);
    }

    /**
     * @return the instance of the class
     */
    public static EventBusManager getInstance() {
        if (instance == null) {
            instance = new EventBusManager();
        }
        return instance;
    }

    public void fireEvent(GwtEvent event){
        handlerManager.fireEvent(event);
    }
    
    public void registerToPeerEvent(final PeerEvent.Handler handler) {
        handlerManager.addHandler(PeerEvent.getType(), handler);
    }
    
    public void registerToDocumentEvent(final DocumentEvent.Handler handler) {
        handlerManager.addHandler(DocumentEvent.getType(), handler);
    }
    
    public void registerToCommentEvent(final CommentEvent.Handler handler) {
        handlerManager.addHandler(CommentEvent.getType(), handler);
    }
    
    public void registerToVoteEvent(final VoteEvent.Handler handler) {
        handlerManager.addHandler(VoteEvent.getType(), handler);
    }
    
    public void registerToCometdEvent(final CometdEvent.Handler handler) {
        handlerManager.addHandler(CometdEvent.getType(), handler);
    }

    public void registerToLoginEvent(final LoginEvent.Handler handler) {
        handlerManager.addHandler(LoginEvent.getType(), handler);
    }
    
    public void registerToTagsEvent(final TagsEvent.Handler handler) {
        handlerManager.addHandler(TagsEvent.getType(), handler);
    }
    
    public void registerToTagEvent(final TagEvent.Handler handler) {
        handlerManager.addHandler(TagEvent.getType(), handler);
    }
    
}